package com.ruoyi.manage.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.manage.domain.TypeTemplate;
import com.ruoyi.manage.mapper.TypeTemplateMapper;
import com.ruoyi.manage.service.IAppTypeTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: wwy
 * @Date: 2021/1/27 12:31
 */
@Service
public class AppTypeTemplateServiceImpl implements IAppTypeTemplateService {
    @Autowired
    private TypeTemplateMapper typeTemplateMapper;

    @Override
    public AjaxResult getTypeTemplateAll() {
        List<TypeTemplate> typeTemplates = typeTemplateMapper.selectAll();
        for (TypeTemplate typeTemplate : typeTemplates) {
            String imageList = typeTemplate.getImageList();
            if(StringUtils.isEmpty(imageList)){
                imageList = "[]";
            }
            List list = JSONObject.parseObject(imageList, List.class);
            typeTemplate.setImageListObj(list);
        }
        return AjaxResult.success(typeTemplates);
    }
}
